package bravo.xc.com.xc_bravo_android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import bravo.xc.com.xc_bravo_android.R;
import bravo.xc.com.xc_bravo_android.beans.MessageResultBeans;

/**
 * Created by HDL on 2017/11/1.
 */

public class orderListViewAdapter extends BaseAdapter {
    private Context mContext;
    private int resourceId;
    private List<MessageResultBeans.DataBean> dataBeans;
    public orderListViewAdapter(Context context , int textViewResourceId, List<MessageResultBeans.DataBean> objects) {
        super();
        this.mContext=context;
        this.resourceId=textViewResourceId;
        this.dataBeans =objects;
        //initData();
    }

    @Override
    public int getCount() {
        return dataBeans.size();
    }

    @Override
    public MessageResultBeans.DataBean getItem(int position) {
        return dataBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder=new Holder();
        if(convertView==null){
            convertView= LayoutInflater.from(mContext).inflate(R.layout.item_order,null);

            holder.tv_order_msg= (TextView)convertView.findViewById(R.id.tv_order_msg);
            holder.tv_order_time= (TextView) convertView.findViewById(R.id.tv_order_time);
            holder.tv_order_state= (TextView) convertView.findViewById(R.id.tv_order_state);
            convertView.setTag(holder);
        }else{
            holder=(Holder)convertView.getTag();
        }
        holder.tv_order_msg.setText(dataBeans.get(position).getOrderNum());
        holder.tv_order_time.setText(dataBeans.get(position).getCreateTime());
        switch (dataBeans.get(position).getStatus()){
            case 0:
                holder.tv_order_state.setText("已购买");
                break;
            case 1:
                holder.tv_order_state.setText("已付款");
                break;
            case 2:
                holder.tv_order_state.setText("已完成");
                break;
            default:
                holder.tv_order_state.setText("");

        }

        //根据isSelected来设置item的选中情况
        notifyDataSetChanged();
        return convertView;
    }

    class Holder{
        TextView tv_order_time;
        TextView tv_order_msg;
        TextView tv_order_state;
    }
}
